from leveldata import *
from enemy import *

# This class contains the functions and methods to deal with the 
# informations form the leveldata.py file
class Stage:
     def __init__(self, stageNumber):
          self.stageNumber = stageNumber
          self.enemyDict = {}
          self.wait = 0
          self.activeStage = deque(stageDictionary[stageNumber])
          self.stageFinnished = False
      
     # update does wait or aquires the next task
     # it interpretes what the task is about, for further information 
     # take a look at leveldata.py
     # also the enemy movement is done         
     def update(self):
          for enemyTuple in self.enemyDict.iteritems():
               enemyTuple[1].move()               
          
          # wait every frame until the counter is 0,
          if self.wait > 0:
               self.wait -= 1
          
          # if the counter is zero, get the next task to do
          else:
               if self.activeStage:
                    task = self.activeStage.popleft()
                    
                    # set the waiting counter
                    if task[0] == 1:
                         self.wait = task[1]
                         
                    # create an enemy
                    elif task[0] == 2:
                         self.enemyDict.update({task[5]:Enemy(task[1], task[2], task[3], task[4], task[5])})

                    # tell an enemy to move
                    elif task[0] == 3:
                         if task[3] in self.enemyDict:
                              self.enemyDict[task[3]].setTarget(task[1], task[2])
                    
                    # let an enemy fire
                    elif task[0] == 4:
                         pass
                    
                    # mark  an enemy as dying, he will vanish when arriving his final target
                    elif task[0] == 5:
                         if task[1] in self.enemyDict:
                              self.enemyDict[task[1]].alive = False

               else:
                    self.stageFinnished = True
